package com.wzh.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wzh.product.entity.UserEntity;
import com.wzh.product.service.UserService;
import com.wzh.common.utils.PageUtils;
import com.wzh.common.utils.R;



/**
 * 
 *
 * @author wzh
 * @email 1281204121@qq.com
 * @date 2022-01-22 21:07:56
 */
@RestController
@RequestMapping("product/user")
public class UserController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 登录
     */
    @RequestMapping("/login")
    public R login(@RequestParam Map<String, Object> params){
        return userService.login(params);
    }

    /**
     * 发送验证码
     */
    @RequestMapping("/sendCode")
    public R sendCode(String tel){
        rabbitTemplate.convertAndSend("msg",tel);
        return R.ok("验证码发送成功");
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{tel}")
    public R info(@PathVariable("tel") String tel){
		UserEntity user = userService.getById(tel);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
		return userService.add(user);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] tels){
		userService.removeByIds(Arrays.asList(tels));

        return R.ok();
    }

}
